home *** CD-ROM | disk | FTP | other *** search
- library db;
-
- uses
- Windows, SysUtils,
- Classes,
- Httpext,
- ISAPISock, DBTables;
-
-
-
- //
- // Called anytime a GET is performed on this DLL
- //
- procedure ProcessGet(sock: TISAPISock);
- begin
- with sock do
- begin
- // Blast out a header
- Writeln('HTTP/1.0 200 OK');
- Writeln('Content-type: text/html');
- Writeln('Expires: 0');
- Writeln('');
-
- HHeader('Database: EMPLOYEE.db', hcGray, hcBlack, hcBlue);
- HPageStart;
-
- HHeading(1, 'Search database...');
-
- // Enter an employee ID
- HFormStart('POST', '/bin/db.dll');
- HLine('Valid Employee IDs are 2,4,8,9...');
- HEditbox('Employee ID:', 'EmpID', '', 15, 15);
- HFormEnd('Submit', 'Clear');
-
- HPageEnd;
- end;
- end;
-
-
- procedure ProcessPost(sock: TISAPISock);
- var
- dBase: TTable;
- i: Integer;
- s: String;
- begin
- with sock do
- begin
- // Blast out a header
- Writeln('HTTP/1.0 200 OK');
- Writeln('Content-type: text/html');
- Writeln('Expires: 0');
- Writeln('');
-
- HHeader('Database: EMPLOYEE.db', hcGray, hcBlack, hcBlue);
- HPageStart;
- dBase:=TTable.Create(nil);
- try
- try
- dBase.Active:=False;
- // This DB and alias are included with the Delphi
- // demo.
- dBase.DatabaseName:='DBDEMOS';
- dBase.TableName:='EMPLOYEE.DB';
- dBase.Active:=True;
-
- HFormStart('POST', '/bin/db.dll');
- HLine('Valid Employee IDs are 2,4,8,9...');
- HEditbox('Employee ID:', 'EmpID', '', 15, 15);
- HFormEnd('Submit', 'Clear');
-
- if dBase.FindKey([ GetFormVal('EmpID') ]) then
- begin
- // find key found what we were looking for. Spill this
- // record to the browser
- HSeparator;
- HHeading(1, 'Record located...');
- HSeparator;
-
- // Iterate through field names
- for i:=0 to dBase.FieldCount-1 do
- begin
- s:=dBase.Fields[i].DisplayLabel+': '+dBase.Fields[i].AsString;
- HLine( s );
- end
- end
- else
- begin
- // Find key didn't work
- HHeading(1, 'Record not found! Database: EMPLOYEE.db');
- end;
- finally
- dBase.Free;
- end;
- except
- HLine('An error occurred reading the database');
- end;
- HPageEnd;
- end;
- end;
-
- // CASE MATTERS FOR THIS FUNCTION NAME
- function GetExtensionVersion(var ver: THSE_VERSION_INFO): Boolean; stdcall;
- begin
- result:=True;
- end;
-
- // CASE MATTERS FOR THIS FUNCTION NAME
- function HttpExtensionProc(var ecb: TEXTENSION_CONTROL_BLOCK): LongInt; stdcall;
- var
- sock: TISAPISock;
- method: String;
- begin
- try
- // Create the socket helper
- sock:=TISAPISock.Create(ecb);
-
- method:=sock.GetServerVariable('REQUEST_METHOD');
- //SetLength(method, 3);
- //method:='GET';
- if method='GET' then
- ProcessGet(sock)
- else if method='POST' then
- ProcessPost(sock)
- else
- begin
- sock.Writeln('HTTP/1.0 200 OK');
- sock.Writeln('Content-type: text/html');
- sock.Writeln('');
- sock.Writeln('Unknown method was: '+method+'.');
- end;
-
-
- // Return a normal status code
- StrLCopy( ecb.lpszLogData, PChar('DLL Finished with no errors'), HSE_LOG_BUFFER_LEN-1);
- Result:=HSE_STATUS_SUCCESS;
-
- // Free the socket
- sock.Free;
- except
- ;
- end;
- end;
-
- // * REQUIRED FOR DYNAMIC BINDING.
- // * Index values aren't need.
- // * Case doesn't matter here.
- exports
- GetExtensionVersion,
- HttpExtensionProc;
-
- begin
- end.
-
-